package cn.virens.common.oauth.subject;

public class SubjectUtils extends InheritableThreadLocal<Subject> {
    private static final SubjectUtils LOCAL = new SubjectUtils();
    private static final SubjectNull NULL = new SubjectNull();

    /**
     * 绑定当前登录令牌
     */
    public static Subject bind(Subject subject) {
        if (subject != null) {
            LOCAL.set(subject);
        }

        return subject;
    }

    /**
     * 获取当前登录令牌
     */
    public static Subject getSubject() {
        return LOCAL.get();
    }

    @Override
    protected Subject initialValue() {
        return NULL;
    }
}
